!function(){
	function $(id){return document.getElementById(id);}
	function fot(o){
		var str=o.value;
		try{
			var j=new Function("return("+str+")")();
			return !parseInt(j,10)?0:parseInt(j,10);
		}catch(err){
			o.value="非法数据";
			return 0;
		}
	}
	function x(i,n){var t=Math.pow(10,n);i=parseInt(t*i,10);return i/t;}
	var sm,wg,mg,wf,mf,pg,gd,bj,rx;
	var smp,wgp,mgp,wfp,mfp,pgp,gdp,bjp,rxp;
	var smk,wgk,mgk,wfk,mfk,pgk,gdk,bjk,rxk;
	function getPrefs1(){
		sm = fot($("sm"));
		wg = fot($("wg"));
		mg = fot($("mg"));
		wf = fot($("wf"));
		mf = fot($("mf"));
		pg = fot($("pg"));
		gd = fot($("gd"));
		bj = fot($("bj"));
		rx = fot($("rx"));
	}
	function getPrefs2(){
		smk = fot($("smk"));
		wgk = fot($("wgk"));
		mgk = fot($("mgk"));
		wfk = fot($("wfk"));
		mfk = fot($("mfk"));
		pgk = fot($("pgk"));
		gdk = fot($("gdk"));
		bjk = fot($("bjk"));
		rxk = fot($("rxk"));

		smp = fot($("smp"))/100;
		wgp = fot($("wgp"))/100;
		mgp = fot($("mgp"))/100;
		wfp = fot($("wfp"))/100;
		mfp = fot($("mfp"))/100;
		pgp = fot($("pgp"))/100;
		gdp = fot($("gdp"))/100;
		bjp = fot($("bjp"))/100;
		rxp = fot($("rxp"))/100;

		sms = fot($("sms"));
		wgs = fot($("wgs"));
		mgs = fot($("mgs"));
		wfs = fot($("wfs"));
		mfs = fot($("mfs"));
		pgs = fot($("pgs"));
		gds = fot($("gds"));
		bjs = fot($("bjs"));
		rxs = fot($("rxs"));

		smw = fot($("smw"));
		wgw = fot($("wgw"));
		mgw = fot($("mgw"));
		wfw = fot($("wfw"));
		mfw = fot($("mfw"));
		pgw = fot($("pgw"));
		gdw = fot($("gdw"));
		bjw = fot($("bjw"));
		rxw = fot($("rxw"));
	}
	function cz(i){return i*(1+(fot($("tlv"))-1)*0.0476);}
	function s1(){
		getPrefs1();
		$("smk").value = x(cz(sm),2);
		$("wgk").value = x(cz(wg),2);
		$("mgk").value = x(cz(mg),2);
		$("wfk").value = x(cz(wf),2);
		$("mfk").value = x(cz(mf),2);
		$("pgk").value = x(cz(pg),2);
		$("gdk").value = x(cz(gd),2);
		$("bjk").value = x(cz(bj),2);
		$("rxk").value = x(cz(rx),2);
		$("nlv").value = fot($("tlv"));
	}
	function s2(){
		getPrefs2();
		$("sml").value = x((smk+sms+smw)*(1+smp),2);
		$("wgl").value = x((wgk+wgs+wgw)*(1+wgp),2);
		$("mgl").value = x((mgk+mgs+mgw)*(1+mgp),2);
		$("wfl").value = x((wfk+wfs+wfw)*(1+wfp),2);
		$("mfl").value = x((mfk+mfs+mfw)*(1+mfp),2);
		$("pgl").value = x((pgk+pgs+pgw)*(1+pgp),2);
		$("gdl").value = x((gdk+gds+gdw)*(1+gdp),2);
		$("bjl").value = x((bjk+bjs+bjw)*(1+bjp),2);
		$("rxl").value = x((rxk+rxs+rxw)*(1+rxp),2);
	}
	$("gogogo1").onsubmit = function(e){
		e=e||window.event;
		s1();
		return false;
	};
	$("gogogo2").onsubmit = function(e){
		e=e||window.event;
		s2();
		return false;
	};
	var wz=[
		[1740,270,270,540,540,120,240,120,240],
		[2460,450,450,900,900,240,480,240,480],
		[4020,720,720,1440,1440,390,780,390,780]
	];
	$("load_wz0").onclick = $("load_wz1").onclick = $("load_wz2").onclick = function(){
		$("smw").value=wz[this.className][0];
		$("wgw").value=wz[this.className][1];
		$("mgw").value=wz[this.className][2];
		$("wfw").value=wz[this.className][3];
		$("mfw").value=wz[this.className][4];
		$("pgw").value=wz[this.className][5];
		$("gdw").value=wz[this.className][6];
		$("bjw").value=wz[this.className][7];
		$("rxw").value=wz[this.className][8];
	};
	function initSelect(){
		var t,o=$("select"),l=$("load");
		o.innerHTML="";
		l.onclick=function(){
			$("sm").value=db_pat[o.value]["紫+4"][0];
			$("wg").value=db_pat[o.value]["紫+4"][1];
			$("mg").value=db_pat[o.value]["紫+4"][2];
			$("wf").value=db_pat[o.value]["紫+4"][3];
			$("mf").value=db_pat[o.value]["紫+4"][4];
			$("pg").value=db_pat[o.value]["紫+4"][5];
			$("gd").value=db_pat[o.value]["紫+4"][6];
			$("bj").value=db_pat[o.value]["紫+4"][7];
			$("rx").value=db_pat[o.value]["紫+4"][8];
		};
		for(var j in db_pat){
			t=document.createElement("option");
			t.value=t.innerHTML=j;
			o.appendChild(t);
		}
	}
	initSelect();
}();